package Modellus.WinUI.ExampleTable;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class InputTable extends JTable
{
    private Font font;

    public InputTable()
    {
        font = new Font("Verdana", Font.PLAIN, 10);
        setName("TableExampleFrame");
        getTableHeader().setName("TableHeader");
        getTableHeader().setOpaque(false);
        getTableHeader().setDefaultRenderer(new TransparentHeaderRenderer());
        getTableHeader().setReorderingAllowed(false);
        setCellSelectionEnabled(false);
        setColumnSelectionAllowed(false);
        setRowSelectionAllowed(false);
        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        setOpaque(false);
        setFocusable(false);
    }

    @Override
    public void paintComponent(Graphics g)
    {
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        super.paintComponent(g2d);
    }

    @Override
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
    {
        Component component = super.prepareRenderer(renderer, row, column);
        if (component instanceof JComponent)
        {
            component.setBackground(new Color(255, 255, 255, 0));
            component.setFont(font);
            ((DefaultTableCellRenderer) renderer).setHorizontalAlignment(SwingConstants.RIGHT);
        }
        return component;
    }

    @Override
    public boolean isCellEditable(int row, int column)
    {
        return false;
    }
}
